package com.sisSaude.utils;

public class MyInteger {

  public static double asDouble(int valor) {
    return valor;
  }

  public static String asString(int valor) {
    return Integer.toString(valor);
  }

  public static int fromString(String valor) {
	if (isValidInt(valor)) 
		return Integer.parseInt(unformatted(valor));
	return 0;
  }

  public static boolean isValidInt(String s) {
    boolean valido;
    try {
        Integer.parseInt(s);
        valido = true;
    }
    catch (Exception e)  {
        valido = false;
    }
    return valido;
  }

  public static String unformatted(String s) {
	    int    i;
	    String result = "";
	    if  (s != null) {
	        for (i = 0; i < s.length(); i++) {
		          if      ( (s.charAt(i) >= '0') && (s.charAt(i) <= '9'))
		  	              result = result + s.charAt(i);
	        }
	    }
	    return result;
	  }
}
